home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-10-30 | 10.1 KB | 472 lines | [TEXT/CWIE] |
- { Buttons.p }
- { Created 10/30/98 1:04 PM by AppMaker }
-
- Unit Buttons;
- Interface
-
- Uses
- Types,
- Quickdraw,
- Controls,
- Dialogs,
- Events,
- Lists,
- Menus,
- Resources,
- TextEdit,
- ToolUtils,
-
- DDocData,
- GadgetsEngine,
- GadgetsDoc,
- AMWindow;
-
- type
- Buttons = object (AMWindow)
-
- {data members}
- mData: DDocData;
- mCapInvisibleLabel: ControlHandle;
- mInvisibleHandle: ControlHandle;
- mStandardHandle: ControlHandle;
- mRightIconHandle: ControlHandle;
- mBevelHandle: ControlHandle;
- mXxHandle: ControlHandle;
- mCapTriangleLabel: ControlHandle;
- mLightHandle: ControlHandle;
- mLeftRightHandle: ControlHandle;
- mRadiosBoxHandle: ControlHandle;
- mRadiosGroupHandle: ControlHandle;
- mRadioButtonHandle: ControlHandle;
- mRadioButton2Handle: ControlHandle;
-
- {methods}
- Procedure Initialize; Override;
-
- Procedure Open (inDoc: GadgetsDoc;
- inData: DDocData);
- Procedure Close; Override;
-
- Procedure Control (whichControl: ControlHandle;
- whichPart: integer;
- where: Point); Override;
- Procedure MouseIn (where: Point;
- modifiers: integer); Override;
- Procedure TypeIn (charCode: SInt16); Override;
- Procedure ExitCurField; Override;
- Procedure DataChanged (inDataID: longint); Override;
- Procedure Resize; Override;
- Procedure Scroll (newValue: integer;
- oldValue: integer); Override;
-
- Function GetEngine: GadgetsEngine;
-
- {$ifc false}
- Procedure UpdateMenus; Override;
- {$endif}
- Function DoCommand (inCommand: longint): Boolean; Override;
-
- Procedure DoUndo;
- Procedure DoCut;
- Procedure DoCopy;
- Procedure DoPaste;
- Procedure DoClear;
- Procedure DoSelectAll;
- Procedure DoShowClipboard;
-
- end;
-
- {----------}
- Procedure CreateButtons (inDoc: GadgetsDoc;
- inData: DDocData);
-
- {----------}
- Implementation
-
- Uses
- Globals,
- ResourceDefs,
- DoScrap,
- Scrolling,
- ControlUtils,
- Miscellany;
-
- const
- kCapInvisibleLabel = 1;
- kInvisibleButton = 2;
- kStandardButton = 3;
- kRightIconButton = 4;
- kBevelButton = 5;
- kXxCheck = 6;
- kCapTriangleLabel = 7;
- kLightButton = 8;
- kLeftRightCheck = 9;
- kRadiosBox = 10;
- kRadiosGroup = 11;
- kRadioButtonRadio = 11;
- kRadioButton2Radio = 12;
-
- {----------}
- Procedure CreateButtons (
- inDoc: GadgetsDoc;
- inData: DDocData);
- var
- winObj: Buttons;
- begin
- winObj := nil;
- New (winObj);
-
- if winObj <> nil then begin
- winObj.Initialize;
- winObj.Open (inDoc, inData);
- end;
- end;
-
- {----------}
- Procedure Buttons.Initialize;
- begin
- Inherited Initialize;
- end;
-
- {----------}
- Function Buttons.GetEngine: GadgetsEngine;
- begin
- GetEngine := GadgetsEngine (mDoc.mEngine);
- end;
-
- {----------}
- Procedure Buttons.Open (
- inDoc: GadgetsDoc;
- inData: DDocData);
- var
- window: WindowPtr;
- wftb: Handle;
- errCode: OSErr;
- begin
- mDoc := inDoc;
- mData := inData;
- mData.AddResponder (self);
-
- window := GetNewCWindow (WIND_Buttons, nil, WindowPtr (-1));
- if inDoc.mEngine.GetFilename <> '' then begin
- SetWTitle (window, inDoc.mEngine.GetFilename);
- end;
- mWindow := window;
- GadgetsDoc (mDoc).mButtonsPtr := window;
-
- WindowPeek (window)^.windowKind := kAMWindowFlag;
- SetWRefCon (window, ord4 (self));
- SetPort (window);
- SetInfo (window);
-
- wftb := GetResource ('Wftb', WIND_Buttons);
-
- errCode := CreateRootControl (window, mRootControl);
-
- vScroll := nil;
- hScroll := nil;
-
-
- mCapInvisibleLabel := GetNewControl (CNTL_CapInvisible, window);
- SetWindowItemFont (mCapInvisibleLabel, wftb, 1);
- SetControlFromTEXT (mCapInvisibleLabel, TEXT_CapInvisible);
-
- mInvisibleHandle := GetNewControl (CNTL_Invisible, window);
- SetWindowItemFont (mInvisibleHandle, wftb, 2);
-
- mStandardHandle := GetNewControl (CNTL_Standard, window);
- SetWindowItemFont (mStandardHandle, wftb, 3);
- SetDefaultState (mStandardHandle, true);
-
- mRightIconHandle := GetNewControl (CNTL_RightIcon, window);
- SetWindowItemFont (mRightIconHandle, wftb, 4);
-
- mBevelHandle := GetNewControl (CNTL_Bevel, window);
- SetWindowItemFont (mBevelHandle, wftb, 5);
- errCode := SetBevelButtonTextPlacement (mBevelHandle, kControlBevelButtonPlaceToRightOfGraphic);
- errCode := SetBevelButtonTextAlignment (mBevelHandle, kControlBevelButtonAlignTextFlushLeft, 0);
- errCode := SetBevelButtonGraphicAlignment (mBevelHandle, kControlBevelButtonAlignLeft, 0, 0);
-
- mXxHandle := GetNewControl (CNTL_Xx, window);
- SetWindowItemFont (mXxHandle, wftb, 6);
- SetControlValue (mXxHandle, ord (mData.GetTriangle));
-
- mCapTriangleLabel := GetNewControl (CNTL_CapTriangle, window);
- SetWindowItemFont (mCapTriangleLabel, wftb, 7);
- SetControlFromTEXT (mCapTriangleLabel, TEXT_CapTriangle);
-
- mLightHandle := GetNewControl (CNTL_Light, window);
- SetWindowItemFont (mLightHandle, wftb, 8);
-
- mLeftRightHandle := GetNewControl (CNTL_LeftRight, window);
- SetWindowItemFont (mLeftRightHandle, wftb, 9);
- SetControlValue (mLeftRightHandle, ord (mData.GetLeftRight));
-
- mRadiosBoxHandle := GetNewControl (CNTL_RadiosBox, window);
- SetWindowItemFont (mRadiosBoxHandle, wftb, 10);
- mRadiosGroupHandle := GetNewControl (CNTL_RadiosGroup, window);
- errCode := EmbedControl (mRadiosGroupHandle, mRadiosBoxHandle);
- mRadioButtonHandle := GetNewControl (CNTL_RadioButton, window);
- errCode := EmbedControl (mRadioButtonHandle, mRadiosGroupHandle);
- SetWindowItemFont (mRadioButtonHandle, wftb, 12);
- errCode := SetBevelButtonGraphicAlignment (mRadioButtonHandle, kControlBevelButtonAlignCenter, 0, 0);
- mRadioButton2Handle := GetNewControl (CNTL_RadioButton2, window);
- errCode := EmbedControl (mRadioButton2Handle, mRadiosGroupHandle);
- SetWindowItemFont (mRadioButton2Handle, wftb, 13);
- errCode := SetBevelButtonGraphicAlignment (mRadioButton2Handle, kControlBevelButtonAlignCenter, 0, 0);
-
- errCode := AdvanceKeyboardFocus (window);
-
- ShowWindow (window);
- end;
-
- {----------}
- Procedure Buttons.Close;
- begin
- mData.RemoveResponder (self);
-
- GadgetsDoc (mDoc).mButtonsPtr := nil;
- SetInfo (nil);
- HideWindow (mWindow);
- DisposeWindow (mWindow);
-
- Dispose (self);
- end;
-
- {----------}
- Procedure Buttons.Control (
- whichControl: ControlHandle;
- whichPart: integer;
- where: Point);
- var
- bounds: Rect;
- newValue: integer;
- partcode: SInt16;
- begin
- ExitCurField ();
-
- if whichControl = mInvisibleHandle then begin
- if TrackClick (mInvisibleHandle, where) then begin
- end;
- end;
- if whichControl = mStandardHandle then begin
- if TrackClick (mStandardHandle, where) then begin
- end;
- end;
- if whichControl = mRightIconHandle then begin
- if TrackClick (mRightIconHandle, where) then begin
- end;
- end;
- if whichControl = mBevelHandle then begin
- if TrackClick (mBevelHandle, where) then begin
- end;
- end;
- if whichControl = mXxHandle then begin
- if TrackCheckbox (mXxHandle, where) then begin
- mData.SetTriangle (GetControlValue (mXxHandle) <> 0);
- end;
- end;
- if whichControl = mLightHandle then begin
- if TrackClick (mLightHandle, where) then begin
- end;
- end;
- if whichControl = mLeftRightHandle then begin
- if TrackCheckbox (mLeftRightHandle, where) then begin
- mData.SetLeftRight (GetControlValue (mLeftRightHandle) <> 0);
- end;
- end;
- if whichControl = mRadiosGroupHandle then begin
- if TrackClick (whichControl, where) then begin
- mData.SetRadios (GetControlValue (mRadiosGroupHandle));
- end;
- end;
- end;
-
- {----------}
- Procedure Buttons.DataChanged (
- inDataID: longint);
- begin
- if inDataID = idTriangle then begin
- SetControlValue (mXxHandle, ord (mData.GetTriangle));
- end;
- if inDataID = idLeftRight then begin
- SetControlValue (mLeftRightHandle, ord (mData.GetLeftRight));
- end;
- if inDataID = idRadios then begin
- SetControlValue (mRadiosGroupHandle, mData.GetRadios);
- end;
- End;
-
- {----------}
- Procedure Buttons.MouseIn (
- where: Point;
- modifiers: integer);
- var
- bounds: Rect;
- begin
- end;
-
- {----------}
- Procedure Buttons.ExitCurField;
- var
- errCode: OSErr;
- focus: ControlHandle;
- begin
- errCode := GetKeyboardFocus (mWindow, focus);
-
- if focus = nil then begin
- { nothing to exit }
-
- end;
- inherited ExitCurField;
- end;
-
- {----------}
- Procedure Buttons.TypeIn (
- charCode: SInt16);
- var
- ch: char;
- errCode: OSErr;
- focus: ControlHandle;
- keyCode: SInt16;
- partcode: SInt16;
- begin
- errCode := GetKeyboardFocus (mWindow, focus);
-
- ch := chr (charCode);
- if (ch = charEnter)
- | (ch = charReturn) then begin
- ExitCurField;
- SimulateClick (mStandardHandle);
- end else if ch = charEsc then begin
- end else if ch = charTab then begin
- DoTab (BAnd (curEvent.modifiers, optionKey) <> 0);
- end else if focus <> nil then begin
- keyCode := BAnd (curEvent.message, keyCodeMask);
- partcode := HandleControlKey (focus, keyCode, charCode, curEvent.modifiers);
- mDoc.mEngine.SetDirty;
- end else begin
- SysBeep (1);
- end;
- end;
-
- {----------}
- Procedure Buttons.Resize;
- begin
- { application-specific code to resize items in window }
- end;
-
- {----------}
- Procedure Buttons.Scroll (
- newValue: integer;
- oldValue: integer);
- begin
- { application-specific code to scroll window }
- if gWhichScroll = vScroll then begin
- end else begin { horizontal }
- end;
- end;
-
- {----------}
- Procedure Buttons.DoUndo;
- begin
- end; {DoUndo}
-
- {----------}
- Procedure Buttons.DoCut;
- var
- curTE: TEHandle;
- begin
- curTE := GetCurTE ();
-
- if curTE <> nil then begin
- TECut (curTE);
- mDoc.mEngine.SetDirty;
- scrapDirty := true;
- end;
- end; {DoCut}
-
- {----------}
- Procedure Buttons.DoCopy;
- var
- curTE: TEHandle;
- begin
- curTE := GetCurTE ();
-
- if curTE <> nil then begin
- TECopy (curTE);
- scrapDirty := true;
- end;
- end; {DoCopy}
-
- {----------}
- Procedure Buttons.DoPaste;
- var
- curTE: TEHandle;
- begin
- curTE := GetCurTE ();
-
- if curTE <> nil then begin
- TEPaste (curTE);
- mDoc.mEngine.SetDirty;
- end;
- end; {DoPaste}
-
- {----------}
- Procedure Buttons.DoClear;
- var
- curTE: TEHandle;
- begin
- curTE := GetCurTE ();
-
- if curTE <> nil then begin
- TEDelete (curTE);
- mDoc.mEngine.SetDirty;
- end;
- end; {DoClear}
-
- {----------}
- Procedure Buttons.DoSelectAll;
- var
- curTE: TEHandle;
- begin
- curTE := GetCurTE ();
-
- if curTE <> nil then begin
- TESetSelect (0, 32767, curTE);
- end;
- end; {DoSelectAll}
-
- {----------}
- Procedure Buttons.DoShowClipboard;
- begin
- end; {DoShowClipboard}
-
- {----------}
- Function Buttons.DoCommand (
- inCommand: longint): Boolean;
- begin
- DoCommand := true;
- case inCommand of
- cmdUndo:
- DoUndo;
- cmdCut:
- DoCut;
- cmdCopy:
- DoCopy;
- cmdPaste:
- DoPaste;
- cmdClear:
- DoClear;
- cmdSelectAll:
- DoSelectAll;
- cmdShowClipboard:
- DoShowClipboard;
-
- otherwise
- DoCommand := false;
- end; {case}
- end;
-
- end.
-